package com.youlai.system.controller;


import com.github.pagehelper.PageInfo;
import com.youlai.system.common.result.Result;
import com.youlai.system.model.entity.Approval;
import com.youlai.system.model.form.AttendUpdateStatusForm;
import com.youlai.system.model.form.EmployForm;
import com.youlai.system.model.query.ApprovalQuery;
import com.youlai.system.model.query.AttendanceQuery;
import com.youlai.system.model.vo.AttendanceRecordVO;
import com.youlai.system.service.IApprovalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 只茂瑞
 * @since 2024-06-25
 */
@RestController
@RequestMapping("api/v1/approval")
@Tag(name = "18.审批管理接口")
@RequiredArgsConstructor
public class ApprovalController {
    private final IApprovalService approvalService;

    @Operation(summary = "审批列表")
    @GetMapping("/list")
    public Result<PageInfo<Approval>> getAttendanceRecords(ApprovalQuery approvalQuery){
        PageInfo<Approval> result = approvalService.getAttendPage(approvalQuery);
        return Result.success(result);
    }

    @Operation(summary = "修改审批状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody Approval approval){
        Integer id = approvalService.updateApprovalStatus(approval);
        return Result.success(id);
    }

    @Operation(summary = "获取考勤基本信息")
    @GetMapping("/{id}/form")
    public Result<Approval> getRoleForm(
            @Parameter(description = "审批id") @PathVariable Long id
    ) {
        Approval approval = approvalService.getApprovalForm(id);
        return Result.success(approval);
    }

    @Operation(summary = "新增审批")
    @PostMapping("/saveStatus")
    public Result saveStatus(@RequestBody Approval approval){
        Integer id = approvalService.saveApprovalStatus(approval);
        return Result.success(id);
    }

}
